/*
 * Copyright 2007 - The JDPF Project Team (http://www.jdpf.org) 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */
package org.jdpf.core.plugins.parameters;

import org.jdpf.core.kernel.exceptions.CoreException;
import org.jdpf.core.kernel.exceptions.CoreExceptionsEnum;

public enum ParametersTypesEnum {

	Int("int"),
	Float("float"),
	Double("double"),
	Boolean("boolean"),
	String("string"),
	URI("uri");
	
	private String parameterType;
	
	ParametersTypesEnum (String parameterType) {
		this.parameterType = parameterType;
	}

	public String getStringValue() {
		return parameterType;
	}
	
	private Boolean equalsIgnoreCase(String textToCompare) {
		return parameterType.equalsIgnoreCase(textToCompare);
	}
	
	public boolean isInt() {
		return this.equals(ParametersTypesEnum.Int);
	}
	
	public boolean isFloat() {
		return this.equals(ParametersTypesEnum.Float);
	}
	
	public boolean isDouble() {
		return this.equals(ParametersTypesEnum.Double);
	}
	
	public boolean isBoolean() {
		return this.equals(ParametersTypesEnum.Boolean);
	}
	
	public boolean isString() {
		return this.equals(ParametersTypesEnum.String);
	}
	
	public boolean isURI() {
		return this.equals(ParametersTypesEnum.URI);
	}
	
	public boolean isNumeric() {
		return (parameterType.equals(ParametersTypesEnum.Int) 
				|| parameterType.equals(ParametersTypesEnum.Float)
				|| parameterType.equals(ParametersTypesEnum.Double));
	}
	
	public static ParametersTypesEnum getParameterType(String typeToReturn) throws CoreException {
		if (ParametersTypesEnum.Int.equalsIgnoreCase(typeToReturn)) {
			return ParametersTypesEnum.Int;
		} else if (ParametersTypesEnum.Float.equalsIgnoreCase(typeToReturn)) {
			return ParametersTypesEnum.Float;
		} else if (ParametersTypesEnum.Double.equalsIgnoreCase(typeToReturn)) {
			return ParametersTypesEnum.Double;
		} else if (ParametersTypesEnum.Boolean.equalsIgnoreCase(typeToReturn)) {
			return ParametersTypesEnum.Boolean;
		} else if (ParametersTypesEnum.String.equalsIgnoreCase(typeToReturn)) {
			return ParametersTypesEnum.String;
		} else if (ParametersTypesEnum.URI.equalsIgnoreCase(typeToReturn)) {
			return ParametersTypesEnum.URI;
		} else throw new CoreException (CoreExceptionsEnum.IllegalParameters, 
				"Parameter type " + typeToReturn + " not recognized. Allowed " +
				"values are {Int, Float, Double, Boolean,String}");
	}
	
	public static boolean isParameterTypeNumeric(ParametersTypesEnum parameterType) {
		return (parameterType.equals(ParametersTypesEnum.Int) 
				|| parameterType.equals(ParametersTypesEnum.Float)
				|| parameterType.equals(ParametersTypesEnum.Double));
	}
}
